import dayjs from "dayjs";
import request from "@/utils/request";
// 初始化数据
export const dataMock = {
  paramId: "2323232323",
  paramName: "Journal C-Diameter (bottom)",
  upperLimitValue: 515.1,
  lowerLimitValue: 280,
  controlDown: 290.2,
  controlUp: 490,
  parameterStandards: 350,
  xdataIndex: [],
  xdata: [],
  ydata: [],
  samplingTypeName: "100%检测",
  workOrderStatus: 1,
  workOrderResult:
    "字符数使用JavaScript字符串长度来衡量。 为文本或文本输入类型设置maxlength prop可以限制输入值的长度。 允许你通过设置 show-word-limit 到true 来显示剩余字数。 使用 maxlength 和 minlength 属性,来控制输入内容的最大字数和最小字数。字符数使用JavaScript字符串长度来衡量。 为文本或文本输入类型设置maxlength prop可以限制输入值的长度。 允许你通过设置 show-word-limit 到true 来显示剩余字数。",
};

// 获取随机数
function getRandomInt(min: number, max: number) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// 获取随机时间
function getRandomTime(count: number) {
  const timeStamp = dayjs().valueOf() + count * 60 * 1000;
  return dayjs(timeStamp).format("YYYY-MM-DD HH:mm");
}

// 获取折线图
export function getSingleDataMock(count: number) {
  const data = JSON.parse(JSON.stringify(dataMock));
  for (let i = 0; i < count; i++) {
    data.xdataIndex.push(i + 1);
    data.ydata.push(getRandomInt(200, 600));
    data.xdata.push(getRandomTime(i));
  }
  return data;
}

export const attachDataMock = [
  {
    pathName: "logic-flow.txt",
    pathUrl: "test/info/1861638516140806144.txt",
  },
  {
    pathName: "No. 189, Grove St, Los Angeles",
    pathUrl: "CA 90036",
  },
  {
    pathName: "No. 189, Grove St, Los Angeles",
    pathUrl: "CA 90036",
  },
  {
    pathName: "No. 189, Grove St, Los Angeles",
    pathUrl: "CA 90036",
  },
  {
    pathName: "No. 189, Grove St, Los Angeles",
    pathUrl: "CA 90036",
  },
];

export function getPieces(seriesData: any) {
  if (
    seriesData.lowerLimitValue != null &&
    seriesData.upperLimitValue != null &&
    seriesData.controlDown != null &&
    seriesData.controlUp != null
  ) {
    return [
      {
        lte: seriesData.lowerLimitValue,
        color: "#ee5253",
      },
      {
        gte: seriesData.upperLimitValue,
        color: "#ee5253",
      },
      {
        lte: seriesData.controlDown,
        gt: seriesData.lowerLimitValue || null,
        color: "#ee5253",
      },
      {
        lt: seriesData.upperLimitValue || null,
        gte: seriesData.controlUp,
        color: "#ee5253",
      },
      {
        lt: seriesData.controlUp,
        gt: seriesData.controlDown,
        color: "#838a9d",
      },
    ];
  } else if (
    seriesData.lowerLimitValue != null &&
    seriesData.upperLimitValue != null &&
    seriesData.controlDown == null &&
    seriesData.controlUp == null
  ) {
    return [
      {
        lte: seriesData.lowerLimitValue,
        color: "#ee5253",
      },
      {
        gte: seriesData.upperLimitValue,
        color: "#ee5253",
      },
      {
        lt: seriesData.upperLimitValue,
        gt: seriesData.lowerLimitValue,
        color: "#838a9d",
      },
    ];
  }
}

export function showLineValue(minValue: any, maxValue: any) {
  if (!minValue && !maxValue) {
    return "无";
  } else {
    return `${minValue || ""}~${maxValue || ""}`;
  }
}

// getLongData(),
// getStateData(),
// geSpecificData(),

// 获取 长期综合数据
export function getLongDataApi(param) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/dmpDosPcm/pcmtimingpoint/singleCurve",
      method: "post",
      data: {
        ...param,
      },
    });
    resolve(data);
  });
}
// 获取 阶段综合数据
export function getStateDataApi(param) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/dmpDosPcm/pcmtimingpoint/singleCurve",
      method: "post",
      data: {
        ...param,
      },
    });
    resolve(data);
  });
}
// 获取 特殊送检数据1
export function getSpecialDataApi(param) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/dmpDosPcm/pcmtimingpoint/singleCurve",
      method: "post",
      data: {
        ...param,
      },
    });
    resolve(data);
  });
}
// 获取 特殊送检数据2
export function getSpecialTwoDataApi(param) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/dmpDosPcm/pcmtimingpoint/singleCurve",
      method: "post",
      data: {
        ...param,
      },
    });
    resolve(data);
  });
}
// 获取 特殊送检数据3
export function getSpecialThreeDataApi(param) {
  return new Promise(async (resolve, reject) => {
    const { data } = await request({
      url: "/dmpDosPcm/pcmtimingpoint/singleCurve",
      method: "post",
      data: {
        ...param,
      },
    });
    resolve(data);
  });
}
